<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <meta name="ctx" th:content="${#httpServletRequest.getContextPath()}"/>
    <link rel="stylesheet" th:href="@{/css/admin/base-v2.css}">
    <link rel="stylesheet" th:href="@{/lib/font-awesome/4.7.0/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{/css/admin/app.css}">
</head>

<body>

<div class="app-page">

    <div class="app-page-content">

        <div class="app-card">
            <div class="app-card-body">
                <div class="app-card-body-con">
                    <form>
                        <div class="form-item row">
                            <div class="label">
                                <label>原始密码</label>
                            </div>
                            <div class="body">
                                <input type="password" value="" placeholder="原始密码" class="originalPassword"
                                       name="originalPassword" data-name="原始密码" data-rule="required"
                                       minlength="5" maxlength="32">

                            </div>
                        </div>
                        <div class="form-item row">
                            <div class="label">
                                <label>新密码</label>
                            </div>
                            <div class="body">
                                <input type="password" value="" placeholder="新密码" class="newPassword" name="newPassword"
                                       data-name="新密码" data-rule="required" minlength="5" maxlength="32">

                            </div>
                        </div>
                        <div class="form-item row">
                            <div class="label">
                                <label>确认密码</label>
                            </div>
                            <div class="body" data-limit="0" data-input-name="" data-data-key="resize">
                                <input type="password" value="" placeholder="确认密码" class="confirmPassword"
                                       name="confirmPassword" data-name="确认密码" data-rule="required" minlength="5"
                                       maxlength="32">

                            </div>
                        </div>
                        <div class="form-item row">
                            <div class="label">
                                <label></label>
                            </div>
                            <div class="body" data-limit="0" data-input-name="" data-data-key="resize">
                                <div class="z-btn-group">
                                    <a class="btn-submit z-btn z-primary">确定</a>
                                </div>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>

</div>

<script th:src="@{/lib/jquery.min.js}"></script>
<script th:src="@{/lib/layer-v3.1.1/layer/layer.js}"></script>
<script th:src="@{/js/popup.js}"></script>
<script th:src="@{/js/form.js}"></script>
<script th:src="@{/js/admin/app.js}"></script>
<script th:src="@{/js/pagination.js}"></script>
<script th:src="@{/lib/daterangepicker/moment.min.js}"></script>
<script th:src="@{/lib/daterangepicker/daterangepicker.js}"></script>
<script type="text/javascript" th:inline="javascript">
    //获取context path
    var context = $("meta[name='ctx']").attr("content") || '';

    $(function () {

        eventEmit();
    })

    function eventEmit() {
        var form = $("form").form({
            submitSelector: ".btn-submit",
            msg: function (msg) {
                popup.tipsTop(msg, 'warning');
            },
            submit: function () {

                var data = {};

                $.each($("form").serializeArray(), function (index, field) {
                    if (data[field.name]) {
                        data[field.name] += "," + field.value;
                    } else {
                        data[field.name] = field.value;
                    }
                })
                $.ajax({
                    type: "POST",
                    url: context + "/user/updatePassword",
                    data: data,
                    success: function (obj) {
                        var code = obj.code;
                        if (code == 0) {
                            popup.tipsTop('修改成功', 'success');
                            setTimeout(function (args) {
                                //跳转到登录页
                                top.location.href = context + "/web/login";
                            }, 500);
                        } else {
                            popup.tipsTop(obj.msg, 'warning');
                        }
                    }
                })
            }
        })
    }

</script>
</body>

</html>